package org.springblade.modules.repair.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.springblade.core.mp.base.BaseServiceImpl;
import org.springblade.core.tool.utils.BeanUtil;
import org.springblade.modules.repair.entity.MaintainCheckSpecialHistory;
import org.springblade.modules.repair.entity.MaintainPlanContent;
import org.springblade.modules.repair.entity.MaintainPlanSpecialConfig;
import org.springblade.modules.repair.entity.MaintainTemplateContent;
import org.springblade.modules.repair.mapper.MaintainCheckSpecialHistoryMapper;
import org.springblade.modules.repair.service.IMaintainPlanContentService;
import org.springblade.modules.repair.service.MaintainCheckSpecialHistoryService;
import org.springblade.modules.repair.service.MaintainPlanSpecialConfigService;
import org.springblade.modules.repair.service.MaintainTemplateContentService;
import org.springblade.modules.repair.vo.SpecialHistoryVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class MaintainCheckSpecialHistoryServiceImpl extends BaseServiceImpl<MaintainCheckSpecialHistoryMapper, MaintainCheckSpecialHistory> implements MaintainCheckSpecialHistoryService {

    @Autowired
    private IMaintainPlanContentService planContentService;
    @Autowired
    private MaintainPlanSpecialConfigService specialConfigService;
    @Autowired
    private MaintainTemplateContentService templateContentService;

    @Override
    public List<SpecialHistoryVO> selectByPlan(Long planId, Long locationTypeId) {
        return baseMapper.selectByPlan(planId, locationTypeId);
    }

    /**
     * 根据任务id 生成专项保养检查项记录
     *
     * @param id
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean addHistory(Long id) {
//
//        MaintainPlanContent planContent = planContentService.getById(id);
//        MaintainPlanSpecialConfig specialConfig = specialConfigService.getOne(Wrappers.<MaintainPlanSpecialConfig>lambdaQuery().eq(MaintainPlanSpecialConfig::getPlanId, id));
//        List<MaintainTemplateContent> templateContents = templateContentService.list(Wrappers.<MaintainTemplateContent>lambdaQuery()
//                .eq(MaintainTemplateContent::getTemplateId, specialConfig.getTemplateId()));
//        List<MaintainCheckSpecialHistory> specialHistories = templateContents.stream().map(e -> {
//            MaintainCheckSpecialHistory specialHistory = new MaintainCheckSpecialHistory();
//            BeanUtil.copy(e, specialHistory);
//            specialHistory.setId(null);
//            specialHistory.setPlanId(id);
//            specialHistory.setElevatorId(planContent.getElevatorId());
//            specialHistory.setTemplateContentId(e.getId());
//            return specialHistory;
//        }).collect(Collectors.toList());
//        return this.saveBatch(specialHistories);
		return null;
    }
}



